
/******************************************************************************
*@file  : hal_pcom.h
*@brief : Header file of PCOM HAL module.
******************************************************************************/

#ifndef __HAL_PCOM_H__
#define __HAL_PCOM_H__

#include "hal.h"

#define PCOM_TIMES 10000
/**
  * @brief   PCOM Init structure definition
  */
  
typedef struct
{
    uint32_t            InSel;          //input select
    uint32_t            VrefSel;        //Vref votage select
    uint32_t            FltCmd;          //filt Cmd
    uint32_t            FltTime;        //filt time
    uint32_t            WaitCnt;        //WaitCnt time
    uint32_t            Trim;        //select trim way
    uint32_t            Vref_Vol;        //return actual reference votage 
}PCOM_InitTypeDef;

typedef struct
{
    PCOM_TypeDef        *Instance;       // Register base address 
    PCOM_InitTypeDef    Init;            // PCOM required parameters 
    uint8_t             OutputLevelOrg;  // PCOM OutputLevel original
    uint8_t             OutputLevel;     // PCOM OutputLevel with filter
} PCOM_HandleTypeDef;
/**
  * @}
  */

/** @defgroup PCOM Vref votage select
  * @{
  */
#define PCOM_INSEL_INP_SEL_1    (0U) 
#define PCOM_INSEL_INP_SEL_2    ( 0x1UL << PCOM_CR_INP_SEL_Pos )
#define PCOM_INSEL_VBAT         ( 0x1UL << PCOM_CR_VBAT_EN_Pos )
/**
  * @}
  */
/** @defgroup PCOM FltCmd select
  * @{
  */
#define PCOM_FLTCMD_DISABLE   (0U) 
#define PCOM_FLTCMD_ENABLE    ( 0x1UL << PCOM_CR_FILT_EN_Pos )

/**
  * @}
  */
/** @defgroup PCOM filt time select
  * @{
  */
#define PCOM_FLTTIME_8_PCLK     (0U)      
#define PCOM_FLTTIME_16_PCLK    ( 0x1UL << PCOM_CR_FILT_SET_Pos )
#define PCOM_FLTTIME_32_PCLK    ( 0x2UL << PCOM_CR_FILT_SET_Pos )
#define PCOM_FLTTIME_64_PCLK    ( 0x3UL << PCOM_CR_FILT_SET_Pos )
#define PCOM_FLTTIME_96_PCLK    ( 0x4UL << PCOM_CR_FILT_SET_Pos )
#define PCOM_FLTTIME_128_PCLK   ( 0x5UL << PCOM_CR_FILT_SET_Pos )
#define PCOM_FLTTIME_192_PCLK   ( 0x6UL << PCOM_CR_FILT_SET_Pos )
#define PCOM_FLTTIME_255_PCLK   ( 0x7UL << PCOM_CR_FILT_SET_Pos )
/**
  * @}
  */
/** @defgroup PCOM TRIM select
  * @{
  */
#define PCOM_TRIM_SOFTWARE   (0U) 
#define PCOM_TRIM_FACTORY    (1U)

/**
  * @}
  */
/** @defgroup  PCOM Private Macros
  * @{
  */
#define IS_PCOM_INSTANCE(_PCOM_)            ((_PCOM_) == PCOM)
#define IS_PCOM_INSEL(_INSEL_)              (((_INSEL_) == PCOM_INSEL_INP_SEL_1) || \
                                             ((_INSEL_) == PCOM_INSEL_INP_SEL_2) || \
                                             ((_INSEL_) == PCOM_INSEL_VBAT))
#define IS_PCOM_VREF_SEL(_VREF_SEL_)              (_VREF_SEL_>=0 && _VREF_SEL_<= 0xff)       

#define IS_PCOM_FLTCMD(_FLTCMD_)              (((_FLTCMD_) == PCOM_FLTCMD_DISABLE) || \
                                             ((_FLTCMD_) == PCOM_FLTCMD_ENABLE))

#define IS_PCOM_FLTTIME(_FLTTIME_)        (((_FLTTIME_) == PCOM_FLTTIME_8_PCLK) || \
                                             ((_FLTTIME_) == PCOM_FLTTIME_16_PCLK) || \
                                             ((_FLTTIME_) == PCOM_FLTTIME_32_PCLK) || \
                                             ((_FLTTIME_) == PCOM_FLTTIME_64_PCLK) || \
                                             ((_FLTTIME_) == PCOM_FLTTIME_96_PCLK) || \
                                             ((_FLTTIME_) == PCOM_FLTTIME_128_PCLK) || \
                                             ((_FLTTIME_) == PCOM_FLTTIME_192_PCLK) || \
                                             ((_FLTTIME_) == PCOM_FLTTIME_255_PCLK))
#define IS_PCOM_WAITCNT(_WAITCNT_)              (_WAITCNT_>=0 && _WAITCNT_<= 0x1ff)     

#define IS_PCOM_TRIM(_TRIM_)              (((_TRIM_) == PCOM_TRIM_SOFTWARE) || \
                                             ((_TRIM_) == PCOM_TRIM_FACTORY))
/**
  * @}
  */


/* Exported functions --------------------------------------------------------*/
HAL_StatusTypeDef HAL_PCOM_DeInit(PCOM_HandleTypeDef* hpcom);
HAL_StatusTypeDef HAL_PCOM_Disable(PCOM_HandleTypeDef* hpcom);
HAL_StatusTypeDef HAL_PCOM_Enable(PCOM_HandleTypeDef* hpcom);
HAL_StatusTypeDef HAL_PCOM_GetOutputLevel(PCOM_HandleTypeDef* hpcom);
HAL_StatusTypeDef HAL_PCOM_Init(PCOM_HandleTypeDef* hpcom);
void HAL_PCOM_MspDeInit(PCOM_HandleTypeDef* hpcom);
void HAL_PCOM_MspInit(PCOM_HandleTypeDef* hpcom);
HAL_StatusTypeDef HAL_PCOM_SelfCalibrate(PCOM_HandleTypeDef *hpcom);
HAL_StatusTypeDef HAL_PCOM_WaitDone_Set_ClR(PCOM_HandleTypeDef *hpcom);
HAL_StatusTypeDef HAL_PCOM_Get_Vref_Vol(PCOM_HandleTypeDef *hpcom);
#endif
